//file per la creazione di tabelle dentro dynamo db

exports.create = function(db, options, titolo, callback){
    db.createTable({
        TableName: options.db.amazon_dynamo_operations_table_name+'_'+titolo,

        AttributeDefinitions: [
            { AttributeName: "doc", AttributeType: "S" },
            { AttributeName: "v", AttributeType: "N"}
        ],
        KeySchema: [
            { AttributeName: "doc", KeyType: "HASH" },
            { AttributeName: "v", KeyType: "RANGE"}
        ],
        ProvisionedThroughput: {
            ReadCapacityUnits: options.db.amazon_dynamo_Read_Capacity_Units,
            WriteCapacityUnits: options.db.amazon_dynamo_Write_Capacity_Units,
        }
        }, 
        function(error, result){
            if (error != null) {
                console.log("Error creating Dynamo operations table");
                console.log(error);
            }
            else {
                db.createTable({
                    TableName: options.db.amazon_dynamo_snapshots_table_name+'_'+titolo,

                    AttributeDefinitions: [
                        { AttributeName: "doc", AttributeType: "S" },
                        { AttributeName: "v", AttributeType: "N"}
                    ],
                    KeySchema: [
                        { AttributeName: "doc", KeyType: "HASH" },
                        { AttributeName: "v", KeyType: "RANGE"}
                    ],
                    ProvisionedThroughput: {
                        ReadCapacityUnits: options.db.amazon_dynamo_Read_Capacity_Units,
                        WriteCapacityUnits: options.db.amazon_dynamo_Write_Capacity_Units,
                    }
                    }, function(error, result){
                        if (error != null) {
                            console.log("Error creating Dynamo snapshots table");
                            console.log(error);
                        }
                        else {
                            console.log("Tabella "+options.db.amazon_dynamo_snapshots_table_name+'_'+titolo+" creata");
                            callback();
                        }
                    }
                )
                console.log("Tabella "+options.db.amazon_dynamo_operations_table_name+'_'+titolo+" creata");
            }
        }
    )
}